package com.ruoyi.partybuilding.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.partybuilding.common.EQueryController;
import com.ruoyi.partybuilding.domain.TeamRecord;
import com.ruoyi.partybuilding.service.impl.OrgServiceImpl;
import lombok.var;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.partybuilding.domain.TeamPerson;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.*;
/**
 * 班子成员Controller
 * 
 * @author he-liangliang@outlook.com
 * @date 2024-11-27
 */
@Api(tags = "班子成员")
@RestController
@RequestMapping("/partybuilding/TeamPerson")
public class TeamPersonController extends EQueryController<TeamPerson>
{
    @Resource
    OrgServiceImpl orgService;
    /**
     * 查询班子成员列表
     */
    @ApiOperation("列表")
    //@PreAuthorize("@ss.hasPermi('partybuilding:TeamPerson:list')")
    @GetMapping("/list")
    public R<Page<TeamPerson>> list(TeamPerson teamPerson, PageDomain pageRequest)
    {
        return queryPage(teamPerson, pageRequest);
    }

    /**
     * 导出班子成员列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('partybuilding:TeamPerson:export')")
    @Log(title = "班子成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeamPerson teamPerson)
    {
        List<TeamPerson> list = queryPage(teamPerson,null).getData().getContent();
        ExcelUtil<TeamPerson> util = new ExcelUtil<TeamPerson>(TeamPerson.class);
        util.exportExcel(response, list, "班子成员数据");
    }

    /**
     * 获取班子成员详细信息
     */
    @ApiOperation("详情")
    //@PreAuthorize("@ss.hasPermi('partybuilding:TeamPerson:query')")
    @GetMapping(value = "/{id}")
    public R<TeamPerson> getInfo(@PathVariable("id") Long id)
    {
        return super.getInfo(id);
    }

    /**
     * 新增班子成员
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('partybuilding:TeamPerson:add')")
    @Log(title = "班子成员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@Validated  @RequestBody TeamPerson teamPerson)
    {
       var teamRecord= queryHelper.queryable(TeamRecord.class).whereById(teamPerson.getTeamId()).firstOrNull();
       teamPerson.setDeptId(teamRecord.getDeptId());
       teamPerson.setDeptName(teamRecord.getDeptName());
        return super.add(teamPerson);
    }

    /**
     * 修改班子成员
     */
    @ApiOperation("编辑")
    @PreAuthorize("@ss.hasPermi('partybuilding:TeamPerson:edit')")
    @Log(title = "班子成员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public R edit(@Validated @RequestBody TeamPerson teamPerson)
    {
        return super.edit(teamPerson);
    }

    /**
     * 删除班子成员
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('partybuilding:TeamPerson:remove')")
    @Log(title = "班子成员", businessType = BusinessType.DELETE)
	@PostMapping("remove/{ids}")
    public R<Long> remove(@PathVariable Long[] ids)
    {
        return super.remove(ids);
    }
}
